package com.zecan.blog.utils;

import com.zecan.blog.common.status.BlogCommonStatus;
import com.zecan.blog.common.BlogResult;
import com.zecan.blog.common.status.CommentStatus;
import com.zecan.blog.common.status.StarGoodStatus;
import com.zecan.blog.common.status.UserStatus;
import com.zecan.blog.controller.exception.BlogException;

/**
 * @ClassName BlogResultUtils
 * @Description
 * @date 2022/10/28 18:49
 * @Version 1.0
 * 返回的工具类
 */

public class BlogResultUtils {


    public static BlogResult ok(Object data) {
        return BlogResult.builder()
                .code(BlogCommonStatus.REQUEST_SUCCESS.getCode())
                .msg(BlogCommonStatus.REQUEST_SUCCESS.getMsg())
                .data(data)
                .build();
    }

    public static BlogResult ok(Object data, String msg) {
        return BlogResult.builder()
                .code(BlogCommonStatus.REQUEST_SUCCESS.getCode())
                .msg(msg)
                .data(data)
                .build();
    }

    public static BlogResult ok(String msg) {
        return BlogResult.builder()
                .code(BlogCommonStatus.REQUEST_SUCCESS.getCode())
                .msg(msg)
                .data(null)
                .build();
    }

    // 其他公共状态码构造器
    public static BlogResult blogStatus(BlogCommonStatus status) {
        return BlogResult.builder().code(status.getCode()).msg(status.getMsg()).build();
    }

    // 用户状态码构造器
    public static BlogResult userStatus(UserStatus status) {
        return BlogResult.builder().code(status.getCode()).msg(status.getMsg()).build();
    }

    public static BlogResult userStatus(Object data, UserStatus status) {
        return BlogResult.builder().code(status.getCode()).msg(status.getMsg()).data(data).build();
    }

    public static BlogResult commentStatus(CommentStatus status) {
        return BlogResult.builder().code(status.getCode()).msg(status.getMsg()).build();
    }

    public static BlogResult StarGoodStatus(StarGoodStatus  status) {
        return BlogResult.builder().code(status.getCode()).msg(status.getMsg()).build();
    }

    public static BlogResult exception(BlogException e) {
        return BlogResult.builder().code(e.getCode()).msg(e.getMsg()).build();
    }
}
